import { LevelData } from "../../Data/LevelData";
import SelectLevelPanel from "../../Panel/SelectLevelPanel";
import LanguageManager from "../../../constant/LanguageManager";

export default class SelectLevelUi extends Laya.Script {

    private parentComponent: fairygui.GComponent;

    private selectLevelPanel:SelectLevelPanel;

    private curLevelData:LevelData;

    public SetData(cpm: fairygui.GComponent, curLevelData: LevelData, selectLevelPanel: SelectLevelPanel): void {
        this.parentComponent = cpm;
        this.selectLevelPanel = selectLevelPanel;
        this.curLevelData = curLevelData;
        this.InitComponent();
    }

    private  InitComponent(){

        let titleTxt =   this.parentComponent.getChild("itemtitle").asLabel;
        titleTxt.text = window.gameFacade.ConfigMng.GetLanguageByKey(LanguageManager.PART) + this.curLevelData.levelNum;

        let itemName =   this.parentComponent.getChild("itemName").asLabel;
        itemName.text = window.gameFacade.ConfigMng.GetLanguageByKey(LanguageManager.LEVEL_NAME+this.curLevelData.id)  ;
       
        // let Starttxt = this.parentComponent.getChild("Starttxt").asLabel;
        // Starttxt.text =  window.gameFacade.ConfigMng.GetLanguageByKey(LanguageManager.START);

        let startBtn =  this.parentComponent.getChild("startBtn").asButton;
        startBtn.onClick(this,this.OnStartBtnClick);
    }

    private  OnStartBtnClick(){
        console.log("关卡："+this.curLevelData.levelNum+"开始了");
        window.gameFacade.LevelMng.PlayInLevel(this.curLevelData);
    }
}